package com.sniff.atp.utils;

import javax.net.ssl.*;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

/**
 * @ProjectName: sniff-atp
 * @Package: com.sniff.atp.utils
 * @ClassName: SslUtils
 * @Description: java类作用描述
 * @Author: zss
 * @CreateDate: 2024/2/20 9:26
 * @UpdateDate: 2024/2/20 9:26
 * @Version: 1.0
 */
public class SslUtils {
//    private static void trustAllHttpsCertificates() throws Exception {
//        TrustManager[] trustAllCerts = new TrustManager[1];
//        TrustManager tm = new miTM();
//        trustAllCerts[0] = tm;
//        SSLContext sc = SSLContext.getInstance("SSL");
//        sc.init(null, trustAllCerts, null);
//        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
//    }
//
//    static class miTM implements TrustManager, X509TrustManager {
//        @Override
//        public X509Certificate[] getAcceptedIssuers() {
//            return null;
//        }
//
//        public boolean isServerTrusted(X509Certificate[] certs) {
//            return true;
//        }
//
//        public boolean isClientTrusted(X509Certificate[] certs) {
//            return true;
//        }
//
//        @Override
//        public void checkServerTrusted(X509Certificate[] certs, String authType)
//                throws CertificateException {
//            return;
//        }
//
//        @Override
//        public void checkClientTrusted(X509Certificate[] certs, String authType)
//                throws CertificateException {
//            return;
//        }
//    }
//
//    /**
//     * 忽略HTTPS请求的SSL证书
//     */
//    public static void ignoreSsl() throws Exception{
//        HostnameVerifier hv = new HostnameVerifier() {
//            @Override
//            public boolean verify(String urlHostName, SSLSession session) {
//                return true;
//            }
//        };
//        System.out.println("已忽略HTTPS请求的SSL证书！");
//        trustAllHttpsCertificates();
//        HttpsURLConnection.setDefaultHostnameVerifier(hv);
//    }
}
